<template>
	<!-- #ifdef APP -->
	<view v-if="isAuditMode==true">开发中敬请期待！！！</view>
	<s-layout v-else title="消息" navbar="inner1" :bgStyle="{
			color: '#fff'
		}" :tabbar="tabbar">
		<IndexTop></IndexTop>
		<System></System>
		<Chat></Chat>
		<s-empty v-if="chatList.length === 0 && loadStatus !== 'loading' && isReady"
			icon="https://liuliangbenben.oss-cn-hangzhou.aliyuncs.com/vocal/data-empty.png" text="暂无数据">
		</s-empty>
		<s-empty v-if="chatList.length === 0 && loadStatus !== 'loading' && !isReady"
			icon="https://liuliangbenben.oss-cn-hangzhou.aliyuncs.com/storage/qita/20250211/23d926e697c5ca4c3c5bdf43a3235fd1.png"
			text="请先登录!">
		</s-empty>
		<uni-load-more v-if="total > 0" :status="loadStatus" :content-text="{
		        contentdown: '上拉加载更多',
		      }" @tap="loadmore" />
	</s-layout>
	<!-- #endif -->
</template>

<script setup>
	import {
		ref,
		computed,
	} from 'vue';
	import {
		onLoad,
		onShow,
		onPullDownRefresh,
		onReachBottom
	} from '@dcloudio/uni-app';
	import sheep from '@/sheep';
	// #ifdef APP
	import IndexTop from '@/im/components/im/indexTop.vue'
	import System from '@/im/components/im/systemList.vue'
	import Chat from '@/im/components/im/chatList.vue'
	import $store from '@/im/store/im';
	const isAuditMode = computed(() => sheep.$store('app').isAuditMode);
	// #endif

	uni.hideTabBar();

	const chatList = computed(() => $store().messageList);
	const iMMyInfo = computed(() => $store().userInfo);
	const isReady = computed(() => $store().isReady)
	const total = computed(() => $store().total)
	const loadStatus = computed(() => $store().loadStatus)

	const tabbar = ref('/im/index')

	onLoad(async (options) => {})

	onPullDownRefresh(() => {
		// #ifdef APP
		$store().getMessageList()
		setTimeout(function() {
			uni.stopPullDownRefresh();
		}, 800);
		// #endif
	})

	onReachBottom(() => {
		// #ifdef APP
		loadmore()
		// #endif
	})

	const loadmore = () => {
		if ($store().loadStatus !== 'noMore') {
			$store().page++
			$store().getMsgList()
		}
	}

	onShow(() => {
		// #ifdef MP-WEIXIN
		if (sheep.$store('user').isLogin) {
			const AreYouIn = uni.getStorageSync('AreYouIn')
			if (!AreYouIn) {
				uni.navigateTo({
					url: '/im/pages/web'
				})
			} else {
				uni.switchTab({
					url: '/pages/index/index'
				})
				uni.setStorageSync('AreYouIn', false)
			}
		} else {
			uni.navigateTo({
				url: '/pages/login/index'
			});
		}
		// #endif
		// #ifdef APP
		$store().resetChat()
		$store().resetGroup()
		$store().showNetwork()
		// #endif
	})
</script>

<style lang="scss" scoped>

</style>